package io.gitee.tziye.core.kv;

import io.gitee.tziye.RenaiClient;
import io.gitee.tziye.common.Constants;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public abstract class KvOperator {

    protected final RenaiClient renaiClient;

    public KvOperator(RenaiClient renaiClient) {
        this.renaiClient = renaiClient;
    }

    public abstract void saveKey(String key, Integer expireSeconds);

    public abstract RenaiKey key(String key);

    public abstract List<RenaiKey> keys(List<String> keys);

    public abstract List<RenaiKey> keys();

    public abstract List<RenaiKey> like(String pattern);

    public abstract List<RenaiKey> regexp(String pattern);

    public abstract List<RenaiValue> values(String key);

    public abstract int total();

    public abstract int size(String key);

    public abstract void expire(String key, int expireSeconds);

    public abstract boolean exists(String key);

    public abstract <T> boolean contains(String key, T value);

    public abstract int clear(String key);

    public abstract <T> boolean remove(String key, T value);

    public abstract <T> int removeValues(String key, Collection<T> values);

    public abstract boolean delete(String key);

    public abstract int delete(Collection<String> keys);

    public abstract void flush();

    public Map<String, Object> procedureParams(String key) {
        Map<String, Object> params = new HashMap<>();
        params.put(Constants.KEY, key);
        return params;
    }

}
